import validate from '@/utils/validate';
export default {
	data(){
		return{
			phoneError: '',
			passwordError:'',
			nameErroe:'',
			genderErroe:'',
			postalCode:'',
			address:'',
			detailed:'',
			codeError:'',
			codeUserError:''
		}
	},
	methods:{
		validatePhone(e) {
		  let phone = e.detail.value 
		  if(!phone){
			  this.phoneError = '请输入手机号';
		  }else if(!validate.validateMobile(phone)){
			  this.phoneError = '请输入正确的手机号';
		  }else{
			  this.phoneError = '';
		  }
		},
		validatePasswoed(e) {
		  let password = e.detail.value 
		  const passwordError = validate.validatePassword(password);
		  if(!password){
			  this.passwordError = '请输入密码';
		  }else if(passwordError){
			  this.passwordError = passwordError;
		  }else{
			  this.passwordError = '';
		  }
		},
		validateName(e){
			let name = e.detail.value 
			if(!name) {
				  this.nameErroe = '请输入姓名';
			}else{
				  this.nameErroe = '';
			}
		},
		// validateUserPhone(e){
		// 	let name = e.detail.value 
		// 	if(!name) {
		// 		  this.phoneError = '请输入手机号码';
		// 	}else{
		// 		  this.phoneError = '';
		// 	}
		// },
		validateCode(e){
			let code = e.detail.value 
			if(!code){
				this.postalCode = '请输入邮政编码'
			}else if(!validate.validatePostalCode(code)){
				this.postalCode = '请输入正确的邮政编码'
			}else{
				this.postalCode = ''
			}
		},
		validatadetailed(e){
			let deta = e.detail.value 
			if(!deta){
				this.detailed = '请输入详细地址'
			}else if(!validate.validateAddress(deta)){
				this.detailed = '地址格式错误'
			}else{
				this.detailed = ''
			}
		},
		validateUserCode(e){
			let userCode = e.detail.value
			if(!userCode){
				this.codeUserError = '请输入验证码'
			}else{
				this.codeUserError = ''
			}
		},
		numDown(){
		  const TIME_COUNT = 30
		  if (!this.timerID) {
		    this.smsbtn.codeCount = TIME_COUNT
		    let smsbtnBum = this.smsbtn.codeCount
		    this.timerID = setInterval(() => {
		      if (smsbtnBum > 1 && smsbtnBum <= TIME_COUNT) {
		        smsbtnBum--
		        this.smsbtn.codeShow = true
		        this.isActive = true
		        this.smsbtn.codeText = `重新获取验证码（${smsbtnBum}）`
		      } else {
		        this.smsbtn.codeShow = false
		        clearInterval(this.timerID)
		        this.timerID = null
		        this.coImg = ''
		        smsbtnBum = 60
		        this.smsbtn.codeText = '获取验证码'
		        this.isActive = false
		      }
		    }, 1000)
		  }
		}
		// else if(!validate.validatePostalCode(code)){
		// 	this.postalCode = '请输入正确的邮政编码'
		// }
	}
}